package com.ww.service.impl;

import com.ww.pojo.WallpaperPraise;
import com.ww.mapper.WallpaperPraiseDao;
import com.ww.service.WallpaperPraiseService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * (WallpaperPraise)表服务实现类
 *
 * @author makejava
 * @since 2022-05-24 17:02:32
 */
@Service("wallpaperPraiseService")
public class WallpaperPraiseServiceImpl implements WallpaperPraiseService {
    @Resource
    private WallpaperPraiseDao wallpaperPraiseDao;

    /**
     * 通过ID查询单条数据
     *
     * @param praiseId 主键
     * @return 实例对象
     */
    @Override
    public WallpaperPraise queryById(Integer praiseId) {
        return this.wallpaperPraiseDao.queryById(praiseId);
    }

    @Override
    public WallpaperPraise checkpraise(Integer userId, Integer wallpaperId) {
        return this.wallpaperPraiseDao.checkpraise(userId,wallpaperId);
    }

    /**
     * 分页查询
     *
     * @param wallpaperPraise 筛选条件
     * @param pageRequest     分页对象
     * @return 查询结果
     */
    @Override
    public Page<WallpaperPraise> queryByPage(WallpaperPraise wallpaperPraise, PageRequest pageRequest) {
        long total = this.wallpaperPraiseDao.count(wallpaperPraise);
        return new PageImpl<>(this.wallpaperPraiseDao.queryAllByLimit(wallpaperPraise, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param wallpaperPraise 实例对象
     * @return 实例对象
     */
    @Override
    public WallpaperPraise insert(WallpaperPraise wallpaperPraise) {
        this.wallpaperPraiseDao.insert(wallpaperPraise);
        return wallpaperPraise;
    }

    /**
     * 修改数据
     *
     * @param wallpaperPraise 实例对象
     * @return 实例对象
     */
    @Override
    public WallpaperPraise update(WallpaperPraise wallpaperPraise) {
        this.wallpaperPraiseDao.update(wallpaperPraise);
        return this.queryById(wallpaperPraise.getPraiseId());
    }

    /**
     * 通过主键删除数据
     *
     * @param praiseId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer praiseId) {
        return this.wallpaperPraiseDao.deleteById(praiseId) > 0;
    }
}
